map(function, iterable, ...)
names=['amit','raj','mohan'] mobj = map(len,names) print(mobj) for item in mobj: print(item) lst=list(mobj) print(lst)
<map object at 0x0000018359114700> 4 3 5 [4,3,5]
def myfun(val): return val.upper() names=['amit','raj','mohan'] mobj=map(myfun,names) print(mobj) for item in mobj: print(item) lst=list(mobj) print(lst)
<map object at 0x0000018359114700> AMIT RAJ MOHAN ['AMIT','RAJ','MOHAN']
def myfun(val1,val2): return val1+' '+val2 fnames=['amit','raj', 'mohan','radha'] lnames=['jain','rathi','joshi'] mobj = map(myfun,fnames,lnames) print(mobj) lst=list(mobj) print(lst)
<map object at 0x0000018359114700> ['amit jain','raj rathi','mohan joshi']
lst=input('Enter Numbers :').split() mobj=map(int,lst) nlst=list(mobj) s=sum(nlst) print("Sum is ",s)
Enter Numbers: 5 11 2 15 4 Sum is 43